package com.koron.css2.serviceManage.impl;


import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.MatrCodeBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.MatrCodeMapper;
import com.koron.css2.serviceManage.queryBean.matrCodeQueryBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

public class MatrCodeQuery implements ServerInterface{
	
	private static Logger logger = LogManager.getLogger(MatrCodeQuery.class);
	
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {

		@SuppressWarnings("rawtypes")
		MessageBean<MatrCodeBean> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", MatrCodeBean.class);

		try {
			matrCodeQueryBean bean = JsonUtils.objectToPojo(req.getData(), matrCodeQueryBean.class);
			MatrCodeMapper mapper = factory.getMapper(MatrCodeMapper.class);
			if (StringUtils.isEmpty(bean.getMatrId())){
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "材料id不能为空", void.class);
			}
			MatrCodeBean matrCodeBean = mapper.selectMatrCodeById(bean.getMatrId());
			info.setData( matrCodeBean);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			logger.error(e.getMessage(), e);
		}
		return info;
	}

}
